import 'package:json_annotation/json_annotation.dart';
import 'dart:convert';

part 'message.g.dart';

@JsonSerializable()
class UserBean extends Object {
  @JsonKey(name: 'name')
  String name;

  @JsonKey(name: 'age')
  int age;

  @JsonKey(name: 'email')
  String email;

  @JsonKey(name: 'car')
  List<Car> car;

  UserBean(
    this.name,
    this.age,
    this.email,
    this.car,
  );

  factory UserBean.fromJson(Map<String, dynamic> srcJson) =>
      _$UserBeanFromJson(srcJson);

  Map<String, dynamic> toJson() => _$UserBeanToJson(this);

  @override
  String toString() {
    var str = jsonEncode(this);
    return str;
  }
}

@JsonSerializable()
class Car extends Object {
  @JsonKey(name: 'name')
  String name;

  @JsonKey(name: 'price')
  int price;

  Car(
    this.name,
    this.price,
  );

  factory Car.fromJson(Map<String, dynamic> srcJson) => _$CarFromJson(srcJson);

  Map<String, dynamic> toJson() => _$CarToJson(this);
}
